package com.yoso.definition;

import org.springframework.beans.BeansException;
import org.springframework.beans.MutablePropertyValues;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.stereotype.Component;

@Component
public class MyUserBeanFactoryPostProcessor implements BeanFactoryPostProcessor {
    @Override
    public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
        System.out.println("1.调用 BeanFactoryPostProcessor 的 postProcessBeanFactory(),执行时机：Bean工厂后处理器，在BeanDefinitionMap填充完毕，Bean实例化之前执行");
        BeanDefinition beanDefinition = beanFactory.getBeanDefinition("myUser");
        MutablePropertyValues pv =  beanDefinition.getPropertyValues();
        if (pv.contains("desc")) {
            pv.addPropertyValue("desc", "在BeanFactoryPostProcessor中修改之后的备忘信息");
        }
    }
}
